<?php 
/**
 * 轮播图管理控制器
 */
class RollPictureController extends AuthController{
	private $model;
	public function __init(){
		parent::__init();
		$this->model = K('RollPicture');
	}
	
	
	public function index(){
		$data = $this->model->all();
		$this->assign('data',$data);
		
		$this->display();
	}
	
	/**
	 * 添加
	 */
	public function add(){
		if(IS_POST){
			if(!$this->model->addRoll()) $this->error($this->model->error);
			$this->success('添加成功');
		}
		
		$this->display();
	}
	
	/**
	 * 编辑
	 */
	public function edit(){
		$rpid = Q('get.rpid',0,'intval');
		if(IS_POST){
			if(!$this->model->edit($rpid)) $this->error($this->model->error);
			$this->success('编辑成功',U('index'));
		}
		//获取旧数据
		$oldData = $this->model->where("rpid={$rpid}")->find();
		$this->assign('oldData',$oldData);
		
		$this->display();
	}
	
	/**
	 * 删除
	 */
	public function del(){
		$rpid = Q('get.rpid',0,'intval');
		$this->model->where("rpid={$rpid}")->del();
		$this->success('删除成功',U('index'));
	}
	
	/**
	 * 上传图片
	 */
	public function upload(){
		 $upload = new Upload('Upload/RollPicture/');
		 $file = $upload->upload();
		 if (empty($file)) {
		 	$this->ajax('上传失败');
		 } else {
		 	$data = $file[0];
			$this->ajax($data);
		 }
		
		
		
	}
	
	/**
	 * 删除图片
	 */
	public function delImg(){
		if(IS_AJAX) $this->error('非法请求');
		$path = Q('post.path');
		unlink($path);
		
		
	}
	
	
	
	
}






















 ?>